<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/28
 * Time: 11:21
 */

namespace app\common\model;



class Files extends BaseModel
{
    protected $autoWriteTimestamp = 'datetime';

    public function category()
    {
        return $this->hasOne('FilesCategory','id','category_id');
    }

    //关联authen表
    public function authen()
    {
        return $this->hasOne('Authen','id','authen_id');
    }

    //将create_time 变为 ...前
    public function getCreateTimeAttr($value)
    {
        $difference = time()-strtotime($value);
        $difference = floor($difference/60);
        if($difference  == 0){
            return '刚刚';
        }
        if($difference < 60){
            return $difference.'分前';
        }
        if($difference >= 60){
            $difference = floor($difference/60);
            if($difference > 24 ){
                $difference = floor($difference/24);
                if($difference > 30){
                    $difference = floor($difference/30);
                    if($difference > 12){
                        $difference = floor($difference/12);
                        return $difference.'年前';
                    }
                    return $difference.'月前';
                }
                return $difference.'天前';
            }
            return $difference.'小时前';
        }
    }
}